//
//  NiubiViewController.m
//  danpin
//
//  Created by chuangjia on 21/10/2015.
//  Copyright © 2015 chuangjia. All rights reserved.
//

#import "NiubiViewController.h"
#import "UMengShare.h"
#import "viewconfig.h"
#import "SVHTTPRequest.h"
#import "WebViewController.h"
#import "NiubiSearchVC.h"
#import "UIImage+GIF.h"
#import <objc/runtime.h>
#import "SearchBarSectionView.h"

#import "FeaturesHeadView.h"
#import "orderconfig.h"
#import "ZHttpCache.h"
#import "QRNavigationController.h"
#import "ZGlobal.h"

//====================
#import "NiubiContentView.h"
#import "NiubiModel.h"

//====================
#import "TopTabControlDefine.h"
#import "ColumnViewController.h"

@interface NiubiViewController ()<QRDelegate,TopTabControlDataSource>
{
    
}
@property (nonatomic, strong) UIView * headerView;
@property (nonatomic, strong) UIImageView * imgLogoView;
@property (nonatomic, strong) UIImageView * imgRightFloatView;



@property (nonatomic, strong) NSTimer * placeholderTimer;
@property(nonatomic, strong) NSArray *keywordsArray;
@property(nonatomic,assign) int currentKeyword;

@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)NSDictionary * dcLogo;
@property(nonatomic,assign) CGFloat yOffsetScrollView;
@property(nonatomic,strong) SearchBarSectionView *searchView;

@property (nonatomic,strong) UIButton *txtKey ;

@property (nonatomic, strong) NSMutableArray *menuListArray;
@property (nonatomic, strong) NSMutableArray *subscribeListArray;
@property (nonatomic, strong) NSMutableArray *defaultShowArray; //展示的数据

//
@property (nonatomic, strong) TopTabControl *tabControl;
@end

@implementation NiubiViewController

@synthesize menuListArray=_menuListArray;
@synthesize subscribeListArray=_subscribeListArray;
@synthesize defaultShowArray=_defaultShowArray;

@synthesize dataArray=_dataArray;;
@synthesize txtKey=_txtKey;

@synthesize searchView=_searchView;

@synthesize tabControl=_tabControl;
- (void)viewDidLoad {
    
    [super viewDidLoad];
    [UMengShare event:CK_INDEX acc:1];
    //
    if (!_menuListArray) {
        _menuListArray =[[NSMutableArray alloc] init];
    }
    if (!_defaultShowArray) {
        _defaultShowArray =[[NSMutableArray alloc] init];
    }
    if (!_subscribeListArray) {
        _subscribeListArray =[[NSMutableArray alloc] init];
    }
    _yOffsetScrollView = 0;
    _currentKeyword = 0;
    //
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshBaoliao)
                                                 name:@"subscribe"
                                               object:nil];
    
    //把搜索框放到section header里面去
    [self initSearchView];
    [self.view bringSubviewToFront:_searchView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self initTabView];
     [ZShare showAnimationView:self.view center:self.view.center];
    [self getmenulist:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.rootViewController.tabbar setHidden:NO];
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.rootViewController.tabbar setHidden:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
-(void)reloadData
{
    [self getmenulist:YES];
}
-(void) refreshBaoliao
{
    [self getmenulist:NO];
}
-(void)scrollToTop
{
    if (self.tabControl && self.defaultShowArray.count>0)
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"scrollToTop" object:nil];
    }else{
        [self reloadData];
    }
}
-(void)dealloc
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    self.menuListArray =nil;
    self.defaultShowArray =nil;
    self.subscribeListArray =nil;
    if (_searchView)
    {
        [_searchView removeFromSuperview];
        _searchView=nil;
    }
    if(self.placeholderTimer)
    {
        if (self.placeholderTimer.isValid) {
            [self.placeholderTimer invalidate];
        }
        self.placeholderTimer=nil;
    }
}

//===============================================
#pragma method 顶部搜索框
//===============================================

-(void)initSearchView
{
    
    if (_searchView)
    {
        [_searchView removeFromSuperview];
        _searchView=nil;
    }
    _searchView = [[SearchBarSectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,74)];
    _searchView.backgroundColor = SEARCH_BAR_COLOR;
    _searchView.alpha = 0.97f;
    
    UIButton *qrCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrCodeBtn.frame = CGRectMake(PHOTO_TIME_PADDING, 20+(54-34)/2, 34 ,34);
    [qrCodeBtn setTitleColor:UIColorFromRGB(0x808080) forState:UIControlStateNormal];
    [qrCodeBtn addTarget:self action:@selector(qrcodeAction) forControlEvents:UIControlEventTouchUpInside];
    [qrCodeBtn setImage:[UIImage imageNamed:@"qrcode.png"] forState:UIControlStateNormal];
    qrCodeBtn.alpha = 0.75;
    [_searchView addSubview:qrCodeBtn];
    
    
    float fLeft = PHOTO_TIME_PADDING + 34 + PHOTO_TIME_PADDING;
    
    UIView *vSearchTxt = [[UIView alloc] initWithFrame:CGRectMake(fLeft , 20+(54-34)/2, _searchView.frame.size.width -fLeft - PHOTO_FRAME_WIDTH , 34)];
    vSearchTxt.backgroundColor = UIColorFromRGB(0xffffff);
    vSearchTxt.layer.cornerRadius = 6;
    vSearchTxt.layer.borderColor =  [UIColor colorWithRed:0.835 green:0.835 blue:0.835 alpha:1].CGColor;//UIColorFromRGB(0x999999).CGColor;
    vSearchTxt.layer.borderWidth = 0.5;
    [_searchView addSubview:vSearchTxt];
    
    //
    _txtKey = [UIButton buttonWithType:UIButtonTypeCustom];
    
    float fLeftText = fLeft + 6;
    
    
    [_txtKey setImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];;
    [_txtKey setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [_txtKey setTitle:@"全球购物搜索..." forState:UIControlStateNormal];
    _txtKey.titleLabel.font = FONT(13);
    _txtKey.backgroundColor = [UIColor clearColor];
    _txtKey.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [_txtKey addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
    [vSearchTxt addSubview:_txtKey];
    
    _txtKey.frame = CGRectMake(PHOTO_FRAME_WIDTH, 0, _searchView.frame.size.width - fLeftText, 34);
    _txtKey.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    _txtKey.imageEdgeInsets =  UIEdgeInsetsMake(2, 0, 0, 0);
    vSearchTxt=nil;
    
    float fImgWidth = 150;
    
    _imgRightFloatView = [[UIImageView alloc]initWithFrame:CGRectZero];//[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo.png"]];
    _imgRightFloatView.frame = CGRectMake(DEVICE_WIDTH - fImgWidth, 0 , fImgWidth, 74);
    _imgRightFloatView.hidden = YES;//默认不显示图片， 待网络线程下载后再显示。
    _imgRightFloatView.alpha = 0;
    
    //自适应图片宽高比例
    _imgRightFloatView.contentMode = UIViewContentModeScaleAspectFit;
    [_searchView addSubview:_imgRightFloatView];
    
    _imgRightFloatView.userInteractionEnabled = YES;
    UITapGestureRecognizer *TapLogo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapLogo:)];
    [_imgRightFloatView addGestureRecognizer:TapLogo];
    TapLogo=nil;
    
    [self.view addSubview:_searchView];
    
    
}

-(void)searchAction
{
    NiubiSearchVC *search =[[NiubiSearchVC alloc] init];
    [self.navigationController pushViewController:search animated:NO];
    search=nil;
}

-(void)singleTapLogo:(UITapGestureRecognizer*)tap
{
//    NSLog(@"用户点击了首页的LOGO！访问网页...");
    if(_dcLogo == nil)
        return;
    NSString* strWebURL = [_dcLogo objectForKey:@"url"];
    [self showWebviewWithURL:strWebURL];
}

- (void) qrcodeAction
{
    QRNavigationController *viewcontroller =[QRNavigationController newWithQRDelegate:self];
    [self presentViewController:viewcontroller animated:YES completion:nil];

}
-(void)qRReaderOK:(id)userinfo
{
    [self dismissViewControllerAnimated:YES completion:nil];

    NSString *strUrl = (NSString*)userinfo;
    if (strUrl.length>0) {
        [self showWebviewWithURL:strUrl];
    }
    
}

-(void)cancelQRReader
{
       [self dismissViewControllerAnimated:YES completion:nil];
}
//===============================================
#pragma method 滚动视图
//===============================================

-(void)initTabView
{
    _tabControl= [[TopTabControl alloc] initWithFrame:CGRectMake(0, 74, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-74-self.rootViewController.tabbar.bounds.size.height)];
    _tabControl.datasource = self;
    [self.view addSubview:_tabControl];
    
}
- (CGFloat)TopTabWidth:(TopTabControl *)tabCtrl itemAtIndex:(NSUInteger)index
{
    if(index >=[self.defaultShowArray count])
    {
        return 0;
    }
    NSDictionary *dict = [self.defaultShowArray objectAtIndex:index];
    NSString *name =[[NSString stringWithFormat:@"%@",[dict objectForKey:@"name"]] replaceNullString];
    CGSize sizeName = [name boundingRectWithSize:CGSizeMake(MAXFLOAT, 0.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT(13)}context:nil].size;
    float width = sizeName.width+PHOTO_FRAME_WIDTH;
 
    return width;
}

- (NSInteger)TopTabMenuCount:(TopTabControl *)tabCtrl
{
    return self.defaultShowArray.count;
}
- (BOOL)haveDot:(TopTabControl *)tabCtrl itemIndex:(NSUInteger)index
{
    BOOL isHave = NO;
    if (self.defaultShowArray.count==0 || index>=self.defaultShowArray.count) {
        return isHave;
    }
    NSDictionary *dict = [self.defaultShowArray objectAtIndex:index];
    NSString *name =[[NSString stringWithFormat:@"%@",[dict objectForKey:@"name"]] replaceNullString];
    if (name.length>0) {
        NSMutableArray *array = [NSMutableArray arrayWithArray:[ZShare sharedInstance].manuallySubscribe];
        if ([array containsObject:name]) {
            isHave = YES;
        }else{
            isHave = NO;
        }
    }      
    return isHave;
}
- (NSString *)TopTabControl:(TopTabControl *)tabCtrl itemIndex:(NSUInteger)index
{
    if(index >=[self.defaultShowArray count])
    {
        return @"";
    }
    NSDictionary *dict = [self.defaultShowArray objectAtIndex:index];
    NSString *name =[dict objectForKey:@"name"];
    return name;
}
- (TopTabPage *)TopTabControl:(TopTabControl *)tabCtrl pageAtIndex:(NSUInteger)index
{
    NiubiContentView *page = [[NiubiContentView alloc] initWithFrame:CGRectMake(0,0,CGRectGetWidth(self.tabControl.bounds),CGRectGetHeight(self.tabControl.bounds)-TopTabControl_Default_TopMenuHeight)];//一定要TopTabControl_Default_TopMenuHeight，否则高度不对
    if (index>=self.defaultShowArray.count) {
        return page;
    }
    NSDictionary *dict = [self.defaultShowArray objectAtIndex:index];
    NSString *tid =[dict objectForKey:@"id"];
    page.actionstring = tid;
    [page reloadData];
    __weak typeof (self) wSelf = self;
    [page setCallBack:^(UIView *v, id data, id key, id index) {
        [wSelf cellActionViews:v obj:data key:key indexPath:index];
    }];
    
    NSString *name =[[NSString stringWithFormat:@"%@",[dict objectForKey:@"name"]] replaceNullString];
    if (name.length>0) {
        NSMutableArray *array = [NSMutableArray arrayWithArray:[ZShare sharedInstance].manuallySubscribe];
        if ([array containsObject:name]) {
            [array removeObject:name];
            [[ZShare sharedInstance] setManuallySubscribe:array];
        }
    }
    
    return page;
}
-(void)TopTabSort:(TopTabControl *)tabCtrl
{
    NSMutableArray *temArray =[NSMutableArray array];
    for (NSDictionary *obj in self.defaultShowArray) {
        NSString *v_name =[[NSString stringWithFormat:@"%@",[obj objectForKey:@"name"]] replaceNullString];
        [temArray addObject:v_name];
    }
    [self orderViewOut:temArray];
}
-(void)cellActionViews:(UIView *)v obj:(id)obj key:(id)key indexPath:(NSIndexPath *)indexPath
{
    if(obj && [obj isKindOfClass:[NSDictionary class]])
    {
        [self showWebview:obj];
    }
}
//===============================================
#pragma method 订阅管理 end
//===============================================
-(BOOL)isRecommend:(NSString*)namestr
{
     NSMutableArray *sortRecommendArray =[NSMutableArray arrayWithArray:[ZShare sharedInstance].recommendChannel];
    __block BOOL issss=NO;
    [sortRecommendArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *dict = (NSDictionary *)obj;
        NSString *name =[dict objectForKey:@"name"];
        if ([name isEqualToString:namestr]) {
            *stop=YES;
            issss = YES;
            return ;
        }
    }];
    return issss;
}
- (void)orderViewOut:(NSMutableArray*)titleArray{
    
   __weak typeof (self) wSelf = self;
    NSMutableArray *selectedA =[NSMutableArray array];
    NSMutableArray *sortSubcribeArray =[NSMutableArray arrayWithArray:[ZShare sharedInstance].subscribeChannel];
    if (sortSubcribeArray ==nil || [sortSubcribeArray count]==0) {
        sortSubcribeArray =[NSMutableArray arrayWithArray:self.subscribeListArray];
    }else{
        [sortSubcribeArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSDictionary *dict = (NSDictionary *)obj;
            NSString *name =[dict stringForKey:@"name" withDefaultValue:@""];
            if (name && name.length>0 && ![wSelf isRecommend:name]) {
                [selectedA addObject:name];
            }
            
        }];
    }
  
    NSMutableArray *optionA =[NSMutableArray array];
    NSMutableArray *sortRecommendArray =[NSMutableArray arrayWithArray:[ZShare sharedInstance].recommendChannel];
    if (sortRecommendArray==nil || [sortRecommendArray count]==0) {
    }else
    {
        
        [sortRecommendArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSDictionary *dict = (NSDictionary *)obj;
            NSString *name =[dict stringForKey:@"name" withDefaultValue:@""];
            if (name && name.length>0) {
                if (dict && [dict isKindOfClass:[NSDictionary class]]) {
                    NSArray *keys =[dict allKeys];
                    if (![keys containsObject:@"subscribe_id"]) {
                        [optionA addObject:name];
                    }
                }
                
            }
        }];
    }
    
    
    ColumnViewController *vc = [[ColumnViewController alloc] init];
    vc.title = self.title;
    vc.view.frame = self.view.bounds;
    [vc.selectedArray addObjectsFromArray:selectedA];
    [vc.optionalArray addObjectsFromArray:optionA];
    vc.sortSubcribeArray = self.subscribeListArray;
    
    [vc setCallBack:^(UIView *v, id so, id oo) {
        if (oo && [oo isKindOfClass:[NSArray class]] && [oo count]>0) {
            NSMutableArray * modelArr2 = [NSMutableArray array];
            [modelArr2 removeAllObjects];
            for (NSString * os in oo) {
                [self.subscribeListArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    NSDictionary *dict = (NSDictionary *)obj;
                    NSString *name =[dict objectForKey:@"name"];
                    if ([os isEqualToString:name]) {
                        [modelArr2 addObject:dict];
                        *stop=YES;
                        return;
                    }
                }];
            }
            [[ZShare sharedInstance] setRecommendChannel:modelArr2];
        }
        if (so && [so isKindOfClass:[NSArray class]] && [so count]>0) {
            NSMutableArray * modelArr = [NSMutableArray array];
            [modelArr removeAllObjects];
            for (NSString * ss in so) {
                [self.subscribeListArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    NSDictionary *dict = (NSDictionary *)obj;
                    NSString *name =[dict objectForKey:@"name"];
                    if ([ss isEqualToString:name]) {
                        [modelArr addObject:dict];
                        *stop=YES;
                        return;
                    }
                }];
            }
            [[ZShare sharedInstance] setSubscribeChannel:modelArr];
            
            wSelf.defaultShowArray =[NSMutableArray arrayWithArray:modelArr];
            [wSelf.tabControl reloadData];
        }
      
      
    }];
    [self.navigationController pushViewController:vc animated:YES];

}

//===============================================
#pragma method 滚动视图
//===============================================
-(void)getmenulist:(BOOL)iscache
{
   
    __weak typeof (self) wSelf = self;
    [NiubiModel menuListWithParams:nil loadCache:iscache  Block:^(NSDictionary *dict, NSInteger page, NSError *error) {
        [ZShare hiddenAnimationView:self.view];
        if (dict && [dict isKindOfClass:[NSDictionary class]]) {
            //公共参数
            NSDictionary* meta = [dict dictionaryObjectForKey:@"meta"];
            if (meta && [meta isKindOfClass:[NSDictionary class]]) {
                
                id after = [meta objectForKey:@"after"];
                if (after && [after isKindOfClass:[NSString class]]) {
                    [ZShare sharedInstance].refreshFooter = after;
                }
                id before = [meta objectForKey:@"before"];
                if (before && [before isKindOfClass:[NSString class]]) {
                    [ZShare sharedInstance].refreshHeader = before;
                }
                //商城
                id hotmail = [meta objectForKey:@"hotmall"];
                if (hotmail && [hotmail isKindOfClass:[NSArray class]]) {
                    [ZShare sharedInstance].hotmail = [NSMutableArray arrayWithArray:hotmail];
                }
                //热门关键词
                id hotwords = [meta objectForKey:@"hotwords"];
                if (hotwords && [hotwords isKindOfClass:[NSArray class]]) {
                    [ZShare sharedInstance].hotwords = [NSMutableArray arrayWithArray:hotwords];
                }
                id logo =[meta objectForKey:@"logo"];
                if (logo && [logo isKindOfClass:[NSDictionary class]]) {
                    //动态显示首页的LOGO, 包括URL
                    [self setLogo:logo];
                }
                id arKeywords = [meta objectForKey:@"placeholder"];
                if(arKeywords && [arKeywords isKindOfClass:[NSArray class]] && [arKeywords count] > 0)
                {
                    wSelf.currentKeyword = 0;
                    wSelf.keywordsArray = arKeywords;
                    
                    if ( !wSelf.placeholderTimer )
                    {
                        wSelf.placeholderTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:wSelf selector:@selector(handlePlaceholderTimer:) userInfo:nil repeats:YES];
                    }
                    [wSelf.placeholderTimer fire];
                }
            }
            //
            id objects = [dict objectForKey:@"objects"];
            if (objects && [objects isKindOfClass:[NSArray class]]&&[objects count]>0) {
                wSelf.menuListArray =[NSMutableArray arrayWithArray:objects];
            }
            id subscribe = [dict objectForKey:@"subscribes"];
            if (subscribe && [subscribe isKindOfClass:[NSArray class]]&&[subscribe count]>0) {
                wSelf.subscribeListArray =[NSMutableArray arrayWithArray:subscribe];
                
                [[ZShare sharedInstance] setSubscribeChannel:subscribe];
                
                wSelf.defaultShowArray =[NSMutableArray arrayWithArray:subscribe];
                [wSelf.tabControl reloadData];
            }
          
        }
    }];
}


//===============================================
#pragma method 顶部搜索框
//===============================================
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
    
}

- (BOOL)isAllNum:(NSString *)string{
    unichar c;
    for (int i=0; i<string.length; i++) {
        c=[string characterAtIndex:i];
        if (!isdigit(c) && c != '$' && c != '.' && c != '-' && c != '+')
        {
            return NO;
        }
    }
    return YES;
}

//todo：以后最好变成云端直接输出这个关键字集合。
//因为买个便宜货的数据结构不好，不得已，才根据文章标题自动分词来获取英文的品牌和型号进行比价。

- (NSArray*) getKeywords :(NSString*) strSearchTerm
{
   // [_words removeAllObjects];
    
    NSMutableArray *words = [[NSMutableArray alloc]init];
    
    if(strSearchTerm == nil || strSearchTerm.length == 0)
    {
        return nil;
    }
    
    
    //    NSString *text = @"i'm a 苹果123。...";
    unsigned long length = [strSearchTerm length];
    
    
    NSString * strEnglishWord = @"";
    
    BOOL bChinese = NO;
    
    for (int i=0; i<length; ++i)
    {
        NSRange range = NSMakeRange(i, 1);
        NSString *subString = [strSearchTerm substringWithRange:range];
        const char *cString = [subString UTF8String];
        if (strlen(cString) == 3)
        {
            bChinese = YES;
        }
        else
        {
            bChinese = NO;
            
            
            //英文字母或者字符
            //if(cString == ' ')
            if([subString isEqual:@" "] || [subString isEqual:@"+"] || [subString isEqual:@"*"])
            {
                //碰到空格，就结束这个单词
                bChinese = YES;
            }
            else
            {
                strEnglishWord = [NSString stringWithFormat:@"%@%@",strEnglishWord,subString];
            }
        }
        
        if(strEnglishWord.length > 0 && bChinese)
        {
            if([self isAllNum:strEnglishWord] == NO)
            {
                [words addObject:strEnglishWord];
            }
            strEnglishWord = @"";
        }
    }
    
    if(strEnglishWord.length > 0)
    {
        if([self isAllNum:strEnglishWord] == NO)
        {
            [words addObject:strEnglishWord];
        }
    }
    
    return words;
}


- (void) showWebview:(NSDictionary*)dict
{
    WebViewController *shaidanweb =[[WebViewController alloc] init];
    shaidanweb.baoliaoDictionary=dict;
    shaidanweb.titlestr = @"index";
    NSString *coupon =[[NSString stringWithFormat:@"%@",[dict objectForKey:@"coupon"]] replaceNullString] ;
    shaidanweb.dikouquan = coupon;
    
    [self.navigationController pushViewController:shaidanweb animated:YES];
    shaidanweb=nil;
}

- (void) showWebviewWithURL:(NSString*) strURL
{
    WebViewController *shaidanweb =[[WebViewController alloc] init];
    shaidanweb.urlstr=strURL;
    shaidanweb.titlestr=@"index";
    [self.navigationController pushViewController:shaidanweb animated:YES];
    shaidanweb=nil;
}


- ( void) resetLogo:(float) fOffset
{
    
    if(_imgLogoView.tag == 1)
    {
        _imgLogoView.tag = 0;
        
    }
}

- (void) setLogo:(NSDictionary*) dcLogo
{
    //动态显示首页的LOGO, 包括URL
    if(dcLogo && [dcLogo isKindOfClass:[NSDictionary class]])
    {
        BOOL needReloadLogo = NO;
        if(_dcLogo == nil)
        {
            needReloadLogo = YES;
        }
        else
        {
            NSString* strLogoURL = [_dcLogo objectForKey:@"image"];
            NSString* strWebURL = [_dcLogo objectForKey:@"url"];
            if([strLogoURL isEqual:[dcLogo objectForKey:@"image"]] == NO
               || [strWebURL isEqual:[dcLogo objectForKey:@"url"]] == NO)
            {
                needReloadLogo = YES;
            }
        }
        
        if(needReloadLogo == YES)
        {
            _dcLogo = dcLogo;
            
            NSString* strLogoURL = [_dcLogo objectForKey:@"image"];
            [_imgRightFloatView sd_setImageWithURL:[NSURL URLWithString:strLogoURL]
                                   completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
             {
                 dispatch_time_t time=dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC);
                 dispatch_after(time, dispatch_get_main_queue(), ^
                 {
                     _imgRightFloatView.hidden = NO;
                     [UIView animateWithDuration:0.5f animations:^
                     {
                         _imgRightFloatView.alpha = 0.85;
                     } completion:^(BOOL finished)
                     {
                         
                     }];
                 });
             }];
            
            
        }
        
    }
}

- (UIColor *) getColor:(NSString*)hexColor
{
    unsigned int red,green,blue;
    NSRange range;
    range.length = 2;
    
    range.location = 0;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&red];
    
    range.location = 2;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&green];
    
    range.location = 4;
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&blue];
    
    return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green / 255.0f) blue:(float)(blue / 255.0f)alpha:1.0f];
}


- (void)handlePlaceholderTimer:(NSTimer *)theTimer
{
    
//    return;
    if(_keywordsArray == nil)
        return;
    
    if(_keywordsArray.count == 0)
        return;
    
    
    if(_currentKeyword >= _keywordsArray.count)
    {
        _currentKeyword = 0;
    }
    
    NSDictionary* dc = [_keywordsArray objectAtIndex:_currentKeyword];
    
    if(dc == nil)
        return;
    
    if([dc isKindOfClass:[NSDictionary class]] == NO)
        return;
    
    NSString * strPlacehoder = [dc objectForKey:@"text"];
    if(strPlacehoder && [strPlacehoder isKindOfClass:[NSString class]] && strPlacehoder.length > 0)
    {
        [_txtKey setTitle:strPlacehoder forState:UIControlStateNormal];
        
        NSString * strTextColor = [dc objectForKey:@"color"];
        if(strTextColor && [strTextColor isKindOfClass:[NSString class]] &&  strTextColor.length == 6 )
        {
            [_txtKey setTitleColor:[self getColor: strTextColor] forState:UIControlStateNormal];
            
        }
    }
    _currentKeyword++;
}

@end
